<template>
  <div class="m-leadTabFrom m-dialog">
    <el-form :model="form.data" :inline="true" ref="addRowDataForm" :rules="form.rules" label-position="left" label-width="140px">
      <div>
        <el-form-item label="广告来源">
          <el-input v-model="form.data.adSource" disabled></el-input>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="广告媒介">
          <el-input v-model="form.data.adMedium" disabled></el-input>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="广告系列">
          <el-input v-model="form.data.adSerial" disabled></el-input>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="渠道来源">
          <el-input v-model="form.data.chlSource" :clearable="isEdit" :disabled="!isEdit"></el-input>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="意向度">
          <el-select v-model="form.data.degree" placeholder="请选择" :clearable="isEdit" :disabled="!isEdit">
            <el-option label="高" value="高"></el-option>
            <el-option label="中" value="中"></el-option>
            <el-option label="低" value="低"></el-option>
            <el-option label="无" value="无"></el-option>
          </el-select>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="曾接触的投资产品">
          <el-select v-model="form.data.ever" placeholder="请选择" :disabled="!isEdit" multiple>
            <el-option label="外汇" value="外汇"></el-option>
            <el-option label="贵金属" value="贵金属"></el-option>
            <el-option label="能源" value="能源"></el-option>
            <el-option label="指数" value="指数"></el-option>
            <el-option label="商品" value="商品"></el-option>
            <el-option label="数字货币" value="数字货币"></el-option>
            <el-option label="证券" value="证券"></el-option>
            <el-option label="期货" value="期货"></el-option>
            <el-option label="期权" value="期权"></el-option>
          </el-select>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="投资经验">
          <el-select v-model="form.data.exp" placeholder="请选择" :clearable="isEdit" :disabled="!isEdit">
            <el-option label="无" value="无"></el-option>
            <el-option label="少于6个月" value="少于6个月"></el-option>
            <el-option label="1年以上" value="1年以上"></el-option>
            <el-option label="5年以上" value="5年以上"></el-option>
          </el-select>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="推荐人客户账号">
          <el-input v-model="form.data.referrer" disabled></el-input>
        </el-form-item>
      </div>
      <div class="flex row-towItem">
        <div>
          <el-form-item label="短信推送次数">
            <el-input v-model="form.data.pushSMS" :clearable="isEdit" :disabled="!isEdit"></el-input>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="邮件推送次数">
            <el-input v-model="form.data.pushEmail" :clearable="isEdit" :disabled="!isEdit"></el-input>
          </el-form-item>
        </div>
      </div>
      <div class="flex row-towItem">
        <div>
          <el-form-item label="QQ推送次数">
            <el-input v-model="form.data.pushQQ" :clearable="isEdit" :disabled="!isEdit"></el-input>
          </el-form-item>
        </div>
        <div></div>
      </div>
      <div class="activeBtns" v-if="isEdit">
        <el-button plain @click="$router.go(-1)">取消</el-button>
        <el-button type="primary" @click="submit" :loading="addLoading">更新</el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
  import * as RealaccountAPI from '@/Api/realaccount'
  import * as Utils from '@/utils'
export default {
  name: 'TheAccountDetailsRe',
  data () {
    return {
      form:{
        data:{},
        rules:{}
      },
      copyForm:null,
      addLoading:false,
    }
  },
  computed:{
    isEdit(){
      if(this.$route.query.type && this.$route.query.type == 'edit') {
        return true;
      } else  {
        return false;
      }
    }
  },
  methods:{
    queryInfo(){
      RealaccountAPI.realaccountInfo12({
        id: this.$route.params.id.split("_")[0],
        account:this.$route.params.id.split("_")[1]
      })
        .then(res => {
          if (res.code != 0) {
            this.$notify({
              title: '温馨提示',
              message: res.msg,
              type: 'warning'
            })
            return;
          }
          this.copyForm = Object.assign({},res.data?res.data:{});
          this.form.data = Object.assign({
            ever:''
          },res.data);
          this.form.data.ever = this.form.data.ever ? this.form.data.ever.split('|') : [];
        })
        .catch(error => {
          console.log(error)
        })
    },
    submit() {
      /*
       * query.type  edit编辑模式
       * query.from  desktop 来自我的桌面
       * query.group  a 分配给我的  b 我关注的
       *
       * */
      let ajaxAddress = null;
      this.addLoading = true;
      if(this.$route.query.from == 'desktop') {
        if(this.$route.query.group == 'a') {
          ajaxAddress =  RealaccountAPI.iarealaccountRefEdit;
        } else  {
          ajaxAddress =  RealaccountAPI.ifrealaccountRefEdit;
        }
      } else {
        ajaxAddress = RealaccountAPI.realaccountRefEdit;
      }
      ajaxAddress(Object.assign(Utils.updateFormItemCopy(this.copyForm),this.form.data,{
        ever:this.form.data.ever.join('|'),
        id:this.$route.params.id.split("_")[0]
      }))
        .then(res => {
          this.addLoading = false;
          if (res.code != 0) {
            this.$notify.warning({
              title: '温馨提示',
              message: res.msg
            })
            return;
          }
          this.$message({
            type: 'success',
            message: '修改成功!'
          });
          this.queryInfo();
        })
        .catch(error => {
          this.addLoading = false;
          console.log(error)
        })
    },
  },
  created(){
    this.queryInfo();
  }
}
</script>

<style scoped lang="scss">
</style>
